let id = 0

class Dep {
    constructor() {
        this.id = id++
        this.sub = []
    }
    depend() {
        Dep.target.addDep(this)
        // this.sub.push(this.target)   当某个watcher中多次使用某个dep时  会有重复
    }
    addSub(watcher) {
        this.sub.push(watcher)
    }

    notify() {
        this.sub.forEach(watcher => watcher.update())
    }


}

Dep.target = null
let stack = [];

Dep.addStack = function (watcher) {
    Dep.target = watcher
    stack.push(watcher)
}

Dep.popStack = function () {
    stack.pop()
    Dep.target = stack[stack.length - 1]
}

export default Dep